// pages/goods/list/index.js
import {reqgoodlist} from '../../api/goods'
Page({
  data: {
    goodsList: [], // 商品列表数据
    isFinish: false, // 判断数据是否加载完毕
    requestdata:{
      page:1,//页码
      limit:6,//每页条数
      category1name:"xianhua",//一级分类名字
      category2name:"hong",//二级分类名字
    }
  },
  
  async getgoodlist(){
    const res= await reqgoodlist(this.data.requestdata)
    this.setData({
      goodsList:res.data
    })
  },
  onShow(){
    this.getgoodlist()
  },
  onLoad(options){
    // 拿到跳转到商品列表前的数据，并赋值给requestdata
    Object.assign(this.data.requestdata,options)
    this.setData({
      requestdata:Object.assign(this.data.requestdata,options)
    })
  },
  async onReachBottom(){
    this.setData({
      "requestdata.page":this.data.requestdata.page+1
    })
    const res= await reqgoodlist(this.data.requestdata)
    this.setData({
      goodsList:[...this.data.goodsList,...res.data]
    })
  },
  onPullDownRefresh(){
    // 重置数据
    this.setData({
    isFinish: false, 
   "requestdata.page":1,
   "requestdata.limit":6
    })
    this.getgoodlist()
    wx.stopPullDownRefresh()
  },
  onShareAppMessage(){
    return {
      title:"分享页面",
      path:"/pages/index/index"
    }
  },
  onShareTimeline(){}
})
